package com.bigfreakindeals.Adapters;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bigfreakindeals.R;
import com.bigfreakindeals.Models.Coupons;
import com.bigfreakindeals.Models.ShareItem;
import com.bigfreakindeals.Protocols.SoapHandlers.PostCommentsHandler;

public class ShareAdapter extends ArrayAdapter {

	private static final int RESOURCE = R.layout.dialog_share;
	private LayoutInflater minflater;
	ShareItem[] objects;
	static class ViewHolder {
		TextView text;
		ImageView icon;
	}

	public ShareAdapter(Context context, ShareItem[] objects) {
		super(context, RESOURCE, objects);
		this.objects = objects;
		minflater = LayoutInflater.from(context);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {

			// inflate a new view and setup the view holder for future use
			convertView = minflater.inflate(RESOURCE, null);

			holder = new ViewHolder();
			holder.text = (TextView) convertView.findViewById(R.id.title);
			holder.icon = (ImageView) convertView.findViewById(R.id.icon);
			convertView.setTag(holder);

		} else {
			// view already defined, retrieve view holder
			holder = (ViewHolder) convertView.getTag();
		}

		// Bind the data efficiently with the holder.
		holder.text.setText(objects[position].getName());
		holder.icon.setImageDrawable(objects[position].getImg());

		return convertView;
	}
}
